package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectByteArraySizeTerminated;
import org.farng.mp3.object.ObjectNumberHashMap;
import org.farng.mp3.object.ObjectStringNullTerminated;

import java.io.IOException;


/**
 * DOCUMENT ME!
 *
 * @author Eric Farng Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodyPIC extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodyPIC object.
     */
    public FrameBodyPIC() {
        //        this.setObject("Text Encoding", new Byte((byte) 0));
        //        this.setObject("Image Format", "");
        //        this.setObject("Picture Type", new Byte((byte) 0));
        //        this.setObject("Description", "");
        //        this.setObject("Picture Data", new byte[0]);
    }

    public FrameBodyPIC(FrameBodyPIC body) {
        super(body);
    }

    /**
     * Creates a new FrameBodyPIC object.
     *
     * @param textEncoding DOCUMENT ME!
     * @param imageFormat DOCUMENT ME!
     * @param pictureType DOCUMENT ME!
     * @param description DOCUMENT ME!
     * @param data DOCUMENT ME!
     */
    public FrameBodyPIC(byte textEncoding, String imageFormat, byte pictureType, String description, byte[] data) {
        this.setObject("Text Encoding", new Byte(textEncoding));
        this.setObject("Image Format", imageFormat);
        this.setObject("Picture Type", new Byte(pictureType));
        this.setObject("Description", description);
        this.setObject("Picture Data", data);
    }

    /**
     * Creates a new FrameBodyPIC object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodyPIC(java.io.RandomAccessFile file)
                 throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @param description DOCUMENT ME!
     */
    public void setDescription(String description) {
        setObject("Description", description);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getDescription() {
        return (String) getObject("Description");
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "PIC" + ((char) 0) + getDescription();
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberHashMap(ObjectNumberHashMap.TEXT_ENCODING, 1));
        objectList.add(new ObjectStringNullTerminated("Image Format"));
        objectList.add(new ObjectNumberHashMap(ObjectNumberHashMap.PICTURE_TYPE, 3));
        objectList.add(new ObjectStringNullTerminated("Description"));
        objectList.add(new ObjectByteArraySizeTerminated("Picture Data"));
    }
}